// Fill out your copyright notice in the Description page of Project Settings.


#include "OverrideWidget/WGIButton.h"
#include "Components/ButtonSlot.h"


void SWGI_Button::Construct(const FArguments& InArgs)
{
	OnResetFocus = InArgs._OnResetFocus;

	SButton::Construct(SButton::FArguments()
		.OnClicked(InArgs._OnClicked)
		.OnPressed(InArgs._OnPressed)
		.OnReleased(InArgs._OnReleased)
		.OnHovered(InArgs._OnHovered)
		.OnUnhovered(InArgs._OnUnhovered)
		.ButtonStyle((InArgs._ButtonStyle))
		.ClickMethod((InArgs._ClickMethod))
		.TouchMethod((InArgs._TouchMethod))
		.PressMethod((InArgs._PressMethod))
		.IsFocusable((InArgs._IsFocusable))
	);

}




FReply SWGI_Button::OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{
	FReply result = SButton::OnMouseButtonDown(MyGeometry, MouseEvent);
	OnResetFocus.ExecuteIfBound();
	return result;
}

FReply SWGI_Button::OnMouseButtonDoubleClick(const FGeometry& InMyGeometry, const FPointerEvent& InMouseEvent)
{
	FReply result = SButton::OnMouseButtonDoubleClick(InMyGeometry, InMouseEvent);
	OnResetFocus.ExecuteIfBound();
	return result;
}

TSharedRef<SWidget> UWGI_Button::RebuildWidget()
{
	MyButton = SNew(SWGI_Button)
		.OnClicked(BIND_UOBJECT_DELEGATE(FOnClicked, SlateHandleClicked))
		.OnPressed(BIND_UOBJECT_DELEGATE(FSimpleDelegate, SlateHandlePressed))
		.OnReleased(BIND_UOBJECT_DELEGATE(FSimpleDelegate, SlateHandleReleased))
		.OnResetFocus_UObject(this, &UWGI_Button::SlateHandleResetFocus)
		.OnHovered_UObject(this, &ThisClass::SlateHandleHovered)
		.OnUnhovered_UObject(this, &ThisClass::SlateHandleUnhovered)
		.ButtonStyle(&WidgetStyle)
		.ClickMethod(ClickMethod)
		.TouchMethod(TouchMethod)
		.PressMethod(PressMethod)
		.IsFocusable(false)
		;

	if (GetChildrenCount() > 0)
	{
		Cast<UButtonSlot>(GetContentSlot())->BuildSlot(MyButton.ToSharedRef());
	}

	return MyButton.ToSharedRef();
}

void UWGI_Button::SlateHandleResetFocus()
{
	OnResetFocus.ExecuteIfBound();
}





